<?php

namespace frontend\modules\commission\components;

use Yii;
use yii\web\ForbiddenHttpException;

/**
 * Controller is the base class for `commission` API controller classes.
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class Controller extends \frontend\components\Controller {

    /**
     * @var \common\logics\MemberLogic|null
     */
    public $member = null;

    /**
     * {@inheritdoc}
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * 设置登录用户模块路由动作时必需登录（依托微信授权机制）
     */
    public function beforeAction($action) {
        if (!parent::beforeAction($action)) {
            return false;
        }
        $identify = $this->user;
        if ($identify == null || $identify->avalidMember == null) {
            throw new ForbiddenHttpException('抱歉，当前功能为会员专属功能，非会员身份禁止访问');
        }
        $this->member = $identify->avalidMember;
        return true;
    }

}
